<?php
/**
 * @author jonathan <jo.link.noir@gmail.com>
 * @version 1.0: jo_link_noir
 * @date 04-06-2010
 */
class U1_Research_DAO extends SW_Structure_DAO_Player
{
	static private $factory = null;


	/**
	 * @return #field
	 */
	static public function getFactory()
	{
		return (self::$factory)
			? self::$factory
			: self::$factory = new self('planet', 'research', null, 'ref_user');
	}


	/**
	 * @param int $id
	 * @param int $group
	 * @param int $level
	 * @param int $id_planet = null
	 * @param int $duration = null
	 * @param array $price = null
	 * @param int $time_end = null
	 * @return U1_Building_Element
	 */
	protected function newElement($id, $group, $level, $id_planet = null, $duration = null, array $price = null, $time_end = null)
	{
		return new U1_Research_Element($id, $group, $level);
	}

	/**
	 * @param SW_Structure_Element $element
	 */
	public function update(SW_Structure_Element $element)
	{
		$method = $this->nameMethodStructure('SW_DAO_Structure::update');
		if (!isset(self::$queries[$method]))
			$this->prepare($method, 'UPDATE '.$this->tableStructure.' SET level=? WHERE id=?');

		self::$queries[$method]->execute(
			array($element->getGain(), $element->getId())
		);
	}

	/**
	 * Ne fait rien
	 * @param SW_Structure $structure
	 * @param SW_Structure_List $list
	 * @param int $timestamp
	 */
	public function down(SW_Structure $structure, SW_Structure_List $list, $timestamp)
	{
	}

	/**
	 * Finit la construction d'un élément
	 * @param SW_Structure_Element $element
	 * @param SW_Structure_List $list
	 */
	public function finish(SW_Structure_Element $element, SW_Structure_List $list)
	{
		$element->setDuration(1);
		$element->setGain($element->getGain() + $list->getLevel());
		parent::finish($element, $list);
	}
}